package com.pureut.equipment.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.pureut.equipment.domain.EquipmentDispatch;
import com.pureut.equipment.domain.EquipmentMaintenance;
import com.pureut.equipment.domain.EquipmentRepair;
import com.pureut.equipment.domain.EquipmentState;
import com.pureut.equipment.domain.dto.EquipmentRepairDto;
import com.pureut.equipment.domain.vo.EquipmentRepairVo;
import com.pureut.equipment.service.IEquipmentRepairService;
import com.sale.common.core.domain.R;
import com.sale.common.core.web.controller.BaseController;
import com.sale.common.log.annotation.Log;
import com.sale.common.log.enums.BusinessType;
import com.sale.common.mybatis.core.page.PageQuery;
import com.sale.common.mybatis.core.page.TableDataInfo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;


/**
 * @Description 设备维修
 * @Param equipmentRepair
 * @Date 23-04-24
 * @Author hl
 **/
@RestController
@RequestMapping("/repair")
public class EquipmentRepairController extends BaseController {

    @Resource
    private IEquipmentRepairService equipmentRepairService;

    /**
     * 查询设备维修
     */
    @SaCheckPermission("device:repair:equipment:list")
    @GetMapping("/list")
    public TableDataInfo<EquipmentRepairDto> list(EquipmentRepairVo equipmentRepairVo, PageQuery pageQuery) {
        return equipmentRepairService.selectRepairList(equipmentRepairVo, pageQuery);
    }

    /**
     * 新增设备维修
     */
    @SaCheckPermission("device:repair:equipment:add")
    @Log(title = "设备维修", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public R<Void> add(@RequestBody EquipmentRepair EquipmentRepair) throws Exception {
        return toAjax(equipmentRepairService.insertEquipmentRepair(EquipmentRepair));
    }

    /**
     * 修改设备维修
     */
    @SaCheckPermission("device:repair:equipment:edit")
    @Log(title = "设备维修", businessType = BusinessType.UPDATE)
    @PutMapping("/edit")
    public R<Void> edit(@RequestBody EquipmentRepair EquipmentRepair) {
        return toAjax(equipmentRepairService.updateEquipmentRepair(EquipmentRepair));
    }

    /**
     * 根据编号获取详细信息
     */
    @SaCheckPermission("device:repair:equipment:query")
    @GetMapping(value = "/{repairId}")
    public R<EquipmentRepairDto> getInfo(@PathVariable("repairId") long repairId) {
        return R.ok(equipmentRepairService.selectRepairById(repairId));
    }

    /**
     * 删除设备维修
     */
    @SaCheckPermission("device:repair:equipment:remove")
    @Log(title = "设备维修", businessType = BusinessType.DELETE)
    @DeleteMapping("/{repairId}")
    public R<Void> remove(@PathVariable("repairId") long repairId) {
        return toAjax(equipmentRepairService.deleteRepairById(repairId));
    }

    /**
     * 派工
     */
    @SaCheckPermission("equipment:repair:dispatch")
    @PutMapping("/dispatch")
    public R<Void> dispatch(@RequestBody EquipmentDispatch equipmentDispatch) {
        return toAjax(equipmentRepairService.dispatchEquipmentRepair(equipmentDispatch));
    }

    /**
     * 维修
     */
    @SaCheckPermission("equipment:repair:maintenance")
    @PutMapping("/maintenance")
    public R<Void> maintenance(@RequestBody EquipmentMaintenance equipmentMaintenance) {
        return toAjax(equipmentRepairService.maintenanceEquipmentRepair(equipmentMaintenance));
    }

    /**
     * 提交审核
     */
    @SaCheckPermission("device:repair:equipment:subExamine")
    @PutMapping("/submit/{repairId}")
    public R<Void> maintenance(@PathVariable("repairId") long repairId) {
        return toAjax(equipmentRepairService.submitEquipmentRepair(repairId));
    }


    /**
     * 审核单据
     */
    @SaCheckPermission("device:repair:equipment:examine")
    @PutMapping("/audit")
    public R<Void> audit(@RequestBody EquipmentState equipmentState) throws Exception {
        return toAjax(equipmentRepairService.auditEquipmentRepair(equipmentState));
    }

    /**
     * 添加知识库
     */
    @SaCheckPermission("equipment:repair:addKnowLedge")
    @GetMapping("/addKnowLedge/{id}")
    public R<Void> addKnowLedge(@PathVariable("id") Long id) throws Exception {
        return toAjax(equipmentRepairService.addKnowLedge(id));
    }


}
